<template>
  <div>
    <!-- <div class="infoChar" ref="checkChartRef"></div> -->
    <div class="head-container">
      <el-input v-model="userName" clearable placeholder="输入学员名称搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init">搜索</el-button>
    </div>
    <div class="app-container">
      <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
        <el-table-column prop="rank" label="排名" width="100" align="center" />
        <el-table-column prop="userName" label="学员名称" align="center" />
        <el-table-column prop="rightCount" label="答对题目" align="center" />
        <el-table-column prop="wrongCount" label="答错题目" align="center" />
        <el-table-column prop="source" label="得分" align="center" />
        <el-table-column prop="isPass" label="是否考核通过" align="center" />
      </el-table>
      <el-pagination
        :total="total"
        :current-page="page + 1"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"/>
    </div>
  </div>
</template>

<script>
  import initData from '@/mixins/initData'
  import echarts from 'echarts'

  export default {
    name: 'index',
    mixins: [initData],
    data() {
      return {
        id: this.$route.query.id,
        userName:''
      }
    },
    watch: {
      data: function() {
        this.$nextTick(() => {
         // this.initCheckScheduleCharts()
        })
      }
    },
    methods: {
      beforeInit() {
        this.url = 'task/schedule-check-list'
        this.params = { page: this.page, size: this.size, taskId:this.id,userName:this.userName  }
        return true
      },
      initCheckScheduleCharts() {
        const xData = this.data.map(item => item.userName)
        const yData = this.data.map(item => item.source)
        const option = {
          title: {
            text: '得分情况',
            x: 'center',
            textStyle: {
              fontSize: 13
            }
          },
          color: ['#73c0de'],
          xAxis: {
            type: 'category',
            data: xData
          },
          yAxis: {
            type: 'value',
            show:false
          },
          series: [{
            data: yData,
            type: 'bar',
            barWidth: 40,
            showBackground: true,
            label: {
              show: true,
              position: 'top',
              color: 'black'
            }
          }]
        }
        this.chart = echarts.init(this.$refs.checkChartRef)
        this.chart.setOption(option)
      }
    }
  }
</script>
<style scoped>
  .infoChar {
    min-height: calc(30vh);
    background-color: #f8f9fc;
    border-radius: 10px;
    margin-bottom: 10px;
    border: 1px solid #eaeefb;
  }
</style>
